<%@ page language="java" contentType="text/html; charset=utf-8"
	import="java.util.*,kk.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
    <title>My JSP 'topicedit.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <%
  	request.setCharacterEncoding("utf-8");
 	Topic t=new Topic(); 
  	TopicDao tdao=new TopicDao();
   	String iss=request.getParameter("submit");
 	String tid="";
 	Long id=null;
   	if(iss.equals("点此删除此主题")){
   		tid=request.getParameter("ntid");
   		id=Long.parseLong(tid);
   		int i=tdao.del(id);
   		if(i>0)
   			out.println("<script>alert('删除主题成功');location.replace('admin.jsp');</script>");
   		else
   		out.println("<script>alert('删除主题失败');hstory.back();</script>");
   	}
   	else if(iss.equals("提交")){
   		tid=request.getParameter("ntid");
   		id=Long.parseLong(tid);
   		String topicName =request.getParameter("modify");
   		Topic t1=tdao.get(id);
   		String name=t1.getTname();
   		if(topicName.equals(""))
   			out.println("<script>alert('主题名不能为空');history.back();</script>");
   		else if(name.equals(topicName))
   			out.println("<script>alert('不能与现有主题名同名');history.back();</script>");
   		else{
   			t.setTid(id);
   			t.setTname(topicName);
   			int i=tdao.update(t);
   			if(i>0)
   				out.println("<script>alert('修改主题成功');location.replace('admin.jsp');</script>");
   			else
   				out.println("<script>alert('修改主题失败');hstory.back();</script>");	
   		}
   	}
   %>	
  </body>
</html>
